package com.sysassist.util;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyListAdapter extends BaseAdapter {
	/** index proc_pic */
	private static int INDEX_PROC_PIC = 0;
	/** index app_name */
	private static int INDEX_APP_NAME = 1;
	/** index proc_name */
	private static int INDEX_PROC_NAME = 2;
	/** index mem_cpu */
	private static int INDEX_MEM_CPU = 3;
	
	private Context context;
	private List<HashMap<String, Object>> list;
	private int resource;
	private String[] from;
	private int[] to;
	
	public MyListAdapter(Context context, List<HashMap<String, Object>> list,
			int resource, String[] from, int[] to) {
		this.context = context;
		this.list = list;
		this.resource = resource;
		this.from = from;
		this.to = to;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = LayoutInflater.from(context.getApplicationContext())
				.inflate(resource, null);
		
		ImageView pic = (ImageView) convertView.findViewById(to[INDEX_PROC_PIC]);
		TextView app_name = (TextView) convertView.findViewById(to[INDEX_APP_NAME]);
		TextView proc_name = (TextView) convertView.findViewById(to[INDEX_PROC_NAME]);
		TextView mem_cpu = (TextView) convertView.findViewById(to[INDEX_MEM_CPU]);
		
		pic.setImageDrawable((Drawable) list.get(position).get(from[INDEX_PROC_PIC]));	
		app_name.setText(list.get(position).get(from[INDEX_APP_NAME]).toString());
		proc_name.setText(list.get(position).get(from[INDEX_PROC_NAME]).toString());
		mem_cpu.setText(list.get(position).get(from[INDEX_MEM_CPU]).toString());
		
		return convertView;
	}

}
